package com.caigou.component;

import com.alibaba.fastjson.JSON;
import com.caigou.bean.cms.entity.SurveyFormStatistics;
import com.caigou.config.RabbitConfig;
import com.caigou.service.CollectionService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

/**
 编写消息的生产者
 */

@Component
public class RabbitProducer{

    private Logger logger = LoggerFactory.getLogger(RabbitProducer.class);

    @Resource
    private AmqpTemplate rabbitTemplate;

    // 发送默认消息
    public void sendDefaultMessage(Map<String, Object> message){
        String strMsg = JSON.toJSONString(message);
        String routerKey = "cms.buildHtmlImage";
        logger.info("send test direct queue with "+ RabbitConfig.DEFAULT_EXCHANGE+": "+strMsg+", routerKey="+routerKey);
        rabbitTemplate.convertAndSend(RabbitConfig.DEFAULT_EXCHANGE, routerKey, strMsg);
    }

    //发送修改作者的消息
    public void  sendArticleAuthorMessage(Map<String, Object> message){
        String strMsg = JSON.toJSONString(message);
        String routerKey = "cms.articleAuthor";
        rabbitTemplate.convertAndSend(RabbitConfig.DEFAULT_EXCHANGE, routerKey, strMsg);
    }

    // 发送爬虫修改消息
    public void sendCollectionChangeMessage(Map<String, Object> message, String routerKey){
        String strMsg = JSON.toJSONString(message);
        logger.info("send test direct queue with "+ RabbitConfig.DEFAULT_EXCHANGE+": "+strMsg+", routerKey="+routerKey);
        rabbitTemplate.convertAndSend(RabbitConfig.DEFAULT_EXCHANGE, routerKey, strMsg);
    }

    // 发送爬智能表单统计消息保存
    public void sendFormSaveStatisticsMessage(SurveyFormStatistics message){
        String strMsg = JSON.toJSONString(message);
        String routerKey = "cms.formSaveStatistics";
        logger.info("send test direct queue with "+ RabbitConfig.DEFAULT_EXCHANGE+": "+strMsg+", routerKey="+routerKey);
        rabbitTemplate.convertAndSend(RabbitConfig.DEFAULT_EXCHANGE, routerKey, strMsg);
    }
}
